package com.piepesken.mediscale.models

import androidx.room.*
import kotlinx.coroutines.flow.Flow

@Entity(tableName = "drugs", indices = arrayOf(Index(value = ["name", "ingredients", "treat", "effect"])))
data class Drug(
    @PrimaryKey(autoGenerate = true) val id: Int,
    val name: String,
    val ingredients: String?,
    val treat: String?,
    val effect: String?
)

@Dao
interface DrugDao {
    @Query("SELECT * FROM drugs WHERE name LIKE :search " +
            "OR ingredients LIKE :search " +
            "OR treat LIKE :search " +
            "OR effect LIKE :search")
    fun getDrugWithContent(search: String): Flow<List<Drug>>

    @Query("SELECT * FROM drugs")
    fun getDrugs(): Flow<List<Drug>>

    @Query("SELECT * FROM drugs WHERE id = :id LIMIT 1")
    fun getDrugById(id: Int): Flow<Drug>
}
